
<?php 
	class Habit_model extends CI_Model{

		function __construct(){
			parent::__construct();
		}

		function get_habit_list($limit = 0, $offset = 0, $condtions = array()){
			$where = '1=1';
			if(!empty($condtions['name'])){
				$where .= " AND name like '%".$data['name']."%'";
			}
			$sql  = "SELECT SQL_CALC_FOUND_ROWS t.*,u.nick as user_name,c.nick as child_name,tt.image from {$this->db->dbprefix}tasks t 
						left join {$this->db->dbprefix}users u on u.id=t.user_id 
						left join {$this->db->dbprefix}user_childrens c on c.id = t.`child_id` 
						left join tiku_task_types tt on tt.id = t.task_type_id
						WHERE $where ORDER BY t.id desc ";

			
			if($limit > 0 || $offset > 0){
				$sql .= " LIMIT $limit, $offset";
			}
			$result = $this->db->query($sql)->result_array();
			if($limit > 0 || $offset > 0){
				$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
				return array("count" => $row_num['row_num'], "result" => $result);
			}else{
				return $result;
			}
		}

}